﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using ExtendedDataTableLibrary;


namespace TestApplication
{
    public partial class frmTest : Form
    {
        public frmTest()
        {
            InitializeComponent();
        }
        ExtendedDataTable extendedDt = new ExtendedDataTable();
        private void Form1_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            ds.ReadXml("SampleData.xml");
            DataTable dt = ds.Tables[0];

            extendedDt.ImportDataTable(dt);

            extendedDt.FormatProperties.ColumnNames["FriendId"] = "Id";
            extendedDt.FormatProperties.ColumnNames["FriendName"] = "Name";
            extendedDt.FormatProperties.ColumnNames["FriendSurname"] = "Surname";
            extendedDt.FormatProperties.ColumnNames["Gender"] = "Gender";
            extendedDt.FormatProperties.ColumnNames["PlayedBy"] = "Played By";
        }

        private void btnToWord_Click(object sender, EventArgs e)
        {
            extendedDt.ToWord(@"C:\Friends.docx");
        }

        private void btnToExcel_Click(object sender, EventArgs e)
        {
            extendedDt.ToExcel(@"C:\Friends.xlsx");
        }

        private void btnToHtml_Click(object sender, EventArgs e)
        {
            MessageBox.Show(extendedDt.ToHTML());
        }

        private void btnSendMail_Click(object sender, EventArgs e)
        {
            extendedDt.MailProperties.SmtpClient.Host = "localhost";
            extendedDt.SendMail("oztamer@hotmail.com", "oztamer@hotmail.com", "Friends");
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            extendedDt.PrintProperties.PrintDocument.DefaultPageSettings.Landscape = true;
            extendedDt.Print();
        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            extendedDt.DataProperties.Connection.ConnectionString = "data source=.;initial catalog=dummy;integrated security=SSPI";
            extendedDt.DataProperties.Command.CommandText = "SELECT * FROM Dummy";
            extendedDt.Fill();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            extendedDt.Update();
        }
    }
}
